var page = 0;
var listUrl="product/product!query?page=";
$(function() {
	fillDepartments();	
	$("div.pagination ul li a").bind("click",function(){
		page = $(this).attr("page");
		var link = listUrl+page+"&rows=10";
		if(deptId=="root"){
			doGet(link);	
		}else{
			var url = link+"&query.fields[0].name=department.id&query.fields[0].value="+deptId;
			doGet(url);
		}
		
		
	});
});
function showProduct(code){
	var url = "product/product!get";
	doPost(url,"bean.code="+code);
}

function removeOne(id) {
	if(!confirm("删除产品:"+id+"?"))return;
	$.ajax({
		url : "product/product!remove",
		data : "bean.code=" + id,
		type:"POST"
	});

}

function newOne(){
	var url = "product/start?action=add";
	doGet(url);
}

// 填充部门控件
function fillDepartments() {
	var depts = $("#depts");
	$.getJSON("admin/department/department!bytype", {
		"bean.id" : "root",
		"bean.departmentType": "Manufacture"
	}, function(data, textStatus, jqXHR) {

		$.each(data, function(i, item) {
			
			var li = $("<button did='"+item.id+"' type='button' class='btn btn-info'>"+item.name+"</button>");
			li.bind("click",function(){
				deptId = $(this).attr("did");	
				page=0;
				var url = listUrl+page+"&rows=10&query.fields[0].name=department.id&query.fields[0].value="+deptId;
				doGet(url);
			});
			depts.append(li);
			
		});			
		
	});
}

function checkfordate(){
	alert("show");
	var date = $('.datepicker').val();
	var rst = date!=null && date!='';
	alert(rst);
	if(!rst){
		alert("请选择日期!");
	}
	return rst;
}